package com.um2.mauction.actions;

import javax.naming.InitialContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import manager.UserManagerBean;
import manager.UserManagerRemote;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.um2.mauction.forms.InscriptionForm;

import entity.Utilisateur;



public class InscriptionAction extends Action{

	 public ActionForward execute(ActionMapping mapping, 
             ActionForm form, 
             HttpServletRequest req, 
             HttpServletResponse res) throws Exception {
		 
		 System.out.println("InscriptionAction");
		 String resultat = null;
		 
		 String login 		= ((InscriptionForm) form).getLogin();		
		 String motDePasse 	= ((InscriptionForm) form).getMotDePasse();			
		 String nom 		= ((InscriptionForm) form).getNom();
		 String prenom 		= ((InscriptionForm) form).getPrenom();
		 String adresse		=((InscriptionForm) form).getAdresse();		
		 String email		=((InscriptionForm) form).getEmail();		
		 
		 UserManagerRemote user_manager=null;
		 Utilisateur u=null;
		 try{
				InitialContext ic = new InitialContext();
				user_manager = (UserManagerRemote)ic.lookup(UserManagerBean.RemoteJNDIName);
				System.out.println("MANAGER:" + user_manager);
				
				user_manager.create(login,motDePasse,nom,prenom,adresse,email);
				resultat = "success";
				
			}
			catch(Exception ex){ System.out.println("ERREUR!!" + ex.getMessage());resultat = "failure";}
			
			
		
		

		 return mapping.findForward(resultat);
}
}
